// MapAndSearch.h - MapAndSearch class
// Implements the A* pathfinding algorithm

#ifndef MAPANDSEARCH_H
#define MAPANDSEARCH_H
#include <queue>
#include "Node.h"
#include "Parser.h"

//When passed to priority_queue as the Compare parameter, this struct allows
//the priority_queue to sort by the Node's f value.
struct NodeComparator : public std::binary_function<Node*, Node*, bool>
{
	bool operator()(const Node *a, const Node *b) const
	{
		return a->getF() > b->getF();
	}
};

typedef std::priority_queue<Node*, std::vector<Node*>, NodeComparator> NodeQueue;

class MapAndSearch
{
	public:
		MapAndSearch(void);
		~MapAndSearch(void);

		void initializeMap(std::string, std::string);
		void printNodes(void);

		void runAStar(void);

	private:
		std::string getStartFromUser(void);
		std::string getDestinationFromUser(void);
		std::string getExcludedPointFromUser(void);
		int calculateFValue(const Node&) const;
		int calculateEuclidianDistance(const Node&, const Node&) const;

		bool newAStar(void);
		void printPathHome(void) const;

		Node* startNodePtr;
		Node* destinationNodePtr;
		NodeMap *nodeMapPtr;
		NodeQueue openList;
};
#endif
